﻿@using PepoBebes.Controllers
@model PepoBebes.Models.Agenda
@{
    ViewBag.Title = "Detalles Evento";
    Layout = null;
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@*@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)*@
@*@Html.ActionLink("Agreagar", "Edit", "Bebes", new { id = Model.bebeID }, new { @class = "editLink2" })
*@
<div id="MadreAjax">
    @*@Ajax.ActionLink("Ajax Test", "Edit", "Madres", new { id = Model.bebe.madre.madreID }, new AjaxOptions { UpdateTargetId = "MadreAjax" })*@
    <fieldset>
        <legend>Madre</legend>
        <h2>
            Dni: @Html.DisplayFor(model => model.bebe.madre.dni)<br />
            Nombre: @Html.DisplayFor(model => model.bebe.madre.apellido)
            @Html.DisplayFor(model => model.bebe.madre.nombre)
        </h2>
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <div class="display-label">
                        Edad</div>
                    <div class="display-field">
                        @Html.DisplayFor(model => model.bebe.madre.edad) años
                    </div>
                </td>
                <td>
                    <div class="display-label">
                        Domicilio</div>
                    <div class="display-field">
                        @Html.DisplayFor(model => model.bebe.madre.domicilio)
                    </div>
                </td>
                <td>
                    <div class="display-label">
                        Telefono</div>
                    <div class="display-field">
                        @Html.DisplayFor(model => model.bebe.madre.telefono)
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="display-fieldl">
                    </div>
                    <div class="display-field">
                        @if (Model.bebe.riesgo.descripcion == "Nada")
                        {
                            <img src="@Url.Content("~/Content/images/female_user.png")" alt="Femenino" width="100" height="100" />
                        }
                        else
                        {
                            if (Model.bebe.riesgo.descripcion == "Poco")
                            { 
                            <img src="@Url.Content("~/Content/images/female_user_warning.png")" alt="Femenino" width="100" height="100" />
                            }
                            else
                            { 
                            <img src="@Url.Content("~/Content/images/female_user_peligro.png")" alt="Femenino" width="100" height="100" />
                            }
                        }
                    </div>
                </td>
                <td>
                    <div class="display-field">
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td>
                                    Localidad: @Html.DisplayFor(model => model.bebe.madre.localidad)<br />
                                    Departamento: @Html.DisplayFor(model => model.bebe.madre.departamento.descripcion)
                                </td>
                                <td>
                                    <img src="@Url.Content("~/Content/images/establecimientoIcon.jpg")" alt="Masculino" width="100" height="100" />
                                    <div class="display-field">
                                        <p>
                                            @*@Html.ActionLink("ver establecimientos del Departamento " + Model.bebe.madre.departamento.descripcion, "Ver", "Establecimientos", new { idDepartamento = Model.bebe.madre.departamentoID }, new { rel = "facebox" })*@
                                            <a href="@Url.Content("~/Establecimientos/EstablecimientosDpto/" + Model.bebe.madre.departamentoID.ToString() + "?height=500&width=500")" title="Establecimientos del Departamento: " class="thickbox">
                                                Ver</a>
                                        </p>
                                            <script src="@Url.Content("~/Scripts/thickbox.js")" type="text/javascript"></script>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>Bebe</legend>
        <table>
            <tr>
                <td>
                    <div class="display-label">
                        Peso</div>
                    <div class="display-field">
                        @Html.DisplayFor(model => model.bebe.peso) gm.
                    </div>
                    <div class="display-label">
                        Edad Gestacional</div>
                    <div class="display-field">
                        @Html.DisplayFor(model => model.bebe.edadGestacional) semanas.
                    </div>
                    <div class="display-label">
                        Diagnostico Presuntivo</div>
                    <div class="display-field">
                        @Html.DisplayFor(model => model.bebe)
                    </div>
                    <div class="display-label">
                        Historia Clinica</div>
                    <div class="display-field">
                        @Html.DisplayFor(model => model.bebe.hc)
                    </div>
                    <div class="display-label">
                        Fecha de Nacimiento</div>
                    <div class="display-field">
                        @Html.DisplayFor(model => model.bebe.fechaNacimiento)
                    </div>
                    <div class="display-label">
                        Edad:
                    </div>
                    <div class="display-field">
                        @((int)(DateTime.Today.Subtract(Model.bebe.fechaNacimiento).TotalDays / 30))
                        meses
                    </div>
                    <div class="display-label">
                        Mama Canguro:
                    </div>
                    <div class="display-field">
                        @if (Model.bebe.mamaCanguro == "Si")
                        { 
                            <p>
                                Si</p> 
                        }
                        else
                        {
                            <p>
                                No</p> 
                        }
                    </div>
                    <div class="display-label">
                        Observaciones</div>
                    <div class="display-field">
                        @Html.DisplayFor(model => model.bebe.historialNeo)
                    </div>
                </td>
                <td>
                    <div class="display-label">
                    </div>
                    <div class="display-field" style="text-align: right">
                        @if (Model.bebe.sexo.descripcion == "Femenino")
                        {
                            <img src="@Url.Content("~/Content/images/babyfemale.png")" alt="Femenino" width="100" height="100" />
                        }
                        else
                        {
                            <img src="@Url.Content("~/Content/images/babymale.png")" alt="Masculino" width="100" height="100" />
                        }
                        <br />
                        @*@if (Model.bebe.riesgo.descripcion == "Nada")
                        {
                            <img src="@Url.Content("~/Content/images/female_user.png")" alt="Femenino" width="100" height="100" />
                        }
                        else
                        {
                            if (Model.bebe.riesgo.descripcion == "Poco")
                            { 
                            <img src="@Url.Content("~/Content/images/female_user_warning.png")" alt="Femenino" width="100" height="100" />
                            }
                            else
                            { 
                            <img src="@Url.Content("~/Content/images/female_user_peligro.png")" alt="Femenino" width="100" height="100" />
                            }
                        }*@
                    </div>
                </td>
            </tr>
        </table>
    </fieldset>
    @Html.ActionLink("Agregar", "Create", "HistorialAgenda", new { idBebe = Model.bebeID }, new { @class = "editLink" })
    <div id="commonMessage">
    </div>
    <div id="updateDialog" title="Guardar Historial">
    </div>
    <script type="text/javascript">
        var linkObj;
        $(function () {
            $(".editLink").button();

            $('#updateDialog').dialog({
                autoOpen: false,
                width: 400,
                resizable: false,
                modal: true,
                buttons: {
                    "Guardar": function () {
                        $("#update-message").html(''); //make sure there is nothing on the message before we continue                         
                        $("#HistorialForm").submit();
                    },
                    "Cancelar": function () {
                        $(this).dialog("close");
                    }
                }
            });

            $(".editLink").click(function () {
                //change the title of the dialgo
                linkObj = $(this);
                var dialogDiv = $('#updateDialog');
                var viewUrl = linkObj.attr('href');
                $.get(viewUrl, function (data) {
                    dialogDiv.html(data);
                    //validation
                    var $form = $("#HistorialForm");
                    // Unbind existing validation
                    $form.unbind();
                    $form.data("validator", null);
                    // Check document for changes
                    $.validator.unobtrusive.parse(document);
                    // Re add validation with changes
                    $form.validate($form.data("unobtrusiveValidation").options);
                    //open dialog
                    dialogDiv.dialog('open');
                });
                return false;
            });

        });


        function updateSuccess() {
            if ($("#update-message").html() == "True") {
                //we update the table's info
                //            var parent = linkObj.closest("tr");
                //            parent.find(".carName").html($("#Name").val());
                //            parent.find(".carDescription").html($("#Description").val());
                //now we can close the dialog
                $('#updateDialog').dialog('close');
                //twitter type notification
                $('#commonMessage').html("Guardado con exito");
                $('#commonMessage').delay(400).slideDown(400).delay(3000).slideUp(400);

                $.get('@Url.Action("row")',
            function (d) {
                addStart(d);

            });
            }
            else {
                $("#update-message").show();
            }
        }

        var page = 1;
        function addStart(d) { $(d).css('opacity', 0).prependTo("#list").animate({ opacity: 1 }, 600, 'easeInCubic'); }
        function addEnd(d) { $(d).css('opacity', 0).appendTo("#list").animate({ opacity: 1 }, 300, 'easeInCubic'); }

        function create(o) {
            $.get('@Url.Action("row")', { id: o.Id },
            function (d) {
                addStart(d);

            });
        }
    </script>
    <div id="historial_container" style="overflow: auto">
        <div class="content">
            <table class="atbl">
                <thead>
                    @Html.Partial("hrow")
                </thead>
                <tbody id="list">
                    @{Html.RenderAction("rows", "Agenda", new { idBebe = Model.bebeID });}
                </tbody>
            </table>
        </div>
    </div>
